home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Tutorial / Script3.vu < prev    next >
Encoding:
Text File  |  1998-06-04  |  3.9 KB  |  116 lines  |  [TEXT/MPS ]

  1. # **********************************************************************
  2. # File:                Script 3.vu
  3. #
  4. # Purpose:            to demonstrate flow-control concepts
  5. #
  6. # Prerequisites:    This script assumes that DrawShapesVU is the
  7. #                    currently active application on the target.
  8. #
  9. # Notes:            If an attempt is made to draw a shape and the shape 
  10. #                    does not materialize, it may be because the shape 
  11. #                    drawn is smaller than DrawShapeVU's minimum shape
  12. #                    size.  It is not a problem with VU.  The number of 
  13. #                    shapes that will be drawn can be changed by altering
  14. #                    the gMaxIterations variable.
  15. #
  16. # Written by:        David Gaxiola
  17. #
  18. # Copyright © 1992 by Apple Computer, Inc., all rights reserved.
  19. #
  20. # **********************************************************************
  21.  
  22. # global variable definitions ******************************************
  23. # All global variables begin with a lowercase “g”
  24. gToolColumn := 18;
  25. gToolRow := { 40, 80, 120 ,160 };
  26. gWindowMod := { 41, 21, -21, -21 };
  27. gWindowDim := { };
  28. gScreenDim := { };
  29. gMaxIterations := 4;
  30. gSaveAsFilename := 'Tutorial 3 Example.ds';
  31. gMinimumShapeSize := { 40, 40 };  # minimum size for all shapes
  32. # Begin main body. *************************************************
  33.  
  34. # preliminary setup:
  35.  
  36. MouseSpeed(10);
  37. Patience(2);
  38.  
  39. # Get information about the screen.
  40. match [ screen rectangle:?gScreenDim menubar:true ];
  41. match [ menu title:?FifthMenu ordinality:5 ];
  42.  
  43. # Create a new file.
  44. println "# Setting up new DrawShapes document.";
  45. select [ menuItem title:'New' m:[menu title:'File' ]];
  46. drag [ window title:/Untitled-≈/ ordinality:1 ] absolute:{ 1, 21 };
  47. size [ window title:/Untitled-≈/ ordinality:1 ] 
  48.         width:( gScreenDim[3] - 2 ) height:( gScreenDim[4] - 22 );
  49. match [ window rectangle:?gWindowDim ordinality:1 ];
  50.  
  51. # Note how one for loop takes the place of dozens of lines of code!
  52. # The "for...each" loop works similarly, but with lists.
  53. for currentIteration := 1 to gMaxIterations do 
  54. begin
  55.     println "# Performing editing.  Loop {currentIteration} of {gMaxIterations}.";
  56.     thisRandomTool := Random( 2, 4 );
  57.     move absolute:{ (gWindowDim[1] + gToolColumn), 
  58.                      (gWindowDim[2] + gToolRow[thisRandomTool]) };
  59.     click;
  60.     xStart := Random( (gWindowDim[1] + gWindowMod[1]), 
  61.                             (gWindowDim[3] + gWindowMod[3])/2 ); # x-coordinate in left half of window
  62.     xStop := Random( (xStart+gMinimumShapeSize[1]), 
  63.                          (gWindowDim[3] + gWindowMod[3]) ); # x-coordinate which meets the minimum requirement
  64.     yStart := Random( (gWindowDim[2] + gWindowMod[2]), 
  65.                          (gWindowDim[4] + gWindowMod[4])/2 ); # y-coordinate in upper half of window
  66.     yStop := Random( (yStart + gMinimumShapeSize[2]), 
  67.                        (gWindowDim[4] + gWindowMod[4]) ); # y-coordinate which meets the minimum requirement
  68.     move absolute:{ xStart, yStart };
  69.     pressMouse;
  70.  
  71. # wait statement for slow targets
  72.  
  73.     wait(1);
  74.     move absolute:{ xStop, yStop };
  75.     releaseMouse;
  76.     
  77. # The if...do...else statement can be used to check for 
  78. # changing cases.
  79.  
  80.     if ( FifthMenu = 'Colors' ) do 
  81.     begin
  82.         theRandomOrder := Random( 1, 7 );
  83.         select[ menuItem ordinality:theRandomOrder 
  84.         menu:[ menu title:'Colors' ]];
  85.     end;
  86. end;
  87.  
  88.  
  89. # Save file with the filename specified in the "gSaveAsFilename" 
  90. # variable
  91.  
  92. println "# Saving and closing document.";
  93. select [ menuItem title:/Save As≈/ menu:[ menu title:'File' ]];
  94. Wait(1); ### for slower targets
  95. type keystrokes:{ gSaveAsFilename, returnKey };
  96.  
  97. # The next if control structure checks to see if another dialog box 
  98. # appears indicating that a file already exists with the same name as 
  99. # thag ] do fied with the gSaveAsFilename variable. If the file is 
  100. # already there, VU overwrites the file.
  101.  
  102. if match [ window style:dialog ] do 
  103. begin
  104.     if match [ button title:'Yes' ] do
  105.     begin
  106.         select [ button title:'Yes' ];
  107.     end;
  108.     else if match [ button title:'Replace' ] do
  109.     begin
  110.         select [ button title:'Replace' ];
  111.     end;
  112. end;
  113.  
  114. close [ window title:gSaveAsFilename ];
  115. # End main body. *************************************************
  116.